package spring.cloud.tasks.executor.listener;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.state.ConnectionStateListener;
import spring.cloud.tasks.executor.common.Lifecycle;
import spring.cloud.tasks.executor.listener.config.TaskConfiguration;
import spring.cloud.tasks.executor.task.TaskExecutor;
import spring.cloud.tasks.executor.utils.zookeeper.NodeCacheOrTreeCacheManager;
import spring.cloud.tasks.executor.utils.zookeeper.Zookeeper;

@Slf4j
@Setter
@Getter
public abstract class ListenerHolder implements Lifecycle {
    public Zookeeper zookeeper;
    public String executorId;
    //
    public String taskId;
    public TaskConfiguration taskConfiguration;
    public NodeCacheOrTreeCacheManager nodeCacheOrTreeCacheManager;
    public TaskExecutor taskExecutor;

    public ListenerHolder(final TaskExecutor taskExecutor) {
        this.zookeeper = taskExecutor.getZookeeper();
        this.executorId = taskExecutor.getExecutorId();
        this.taskId = taskExecutor.getTaskId();
        this.taskConfiguration = taskExecutor.getTaskConfiguration();
        this.nodeCacheOrTreeCacheManager = taskExecutor.getNodeCacheOrTreeCacheManager();
        this.taskExecutor = taskExecutor;
    }

    public abstract void start();

    protected void addConnectionStateListener(final ConnectionStateListener connectionStateListener) {
        zookeeper.addConnectionStateListener(connectionStateListener);
    }

    protected void removeConnectionStateListener(final ConnectionStateListener connectionStateListener) {
        zookeeper.removeConnectionStateListener(connectionStateListener);
    }

    @Override
    public void stop() {
    }
}
